/**
* location.search 请求查询参数处理的前端处理工具库
* version 0.1 2017-08-02
* author: rocbin asboot#qq.com
* license: MIT license !
*/
(function(global) {
    var locationSearch = {};
    locationSearch.getSearchParams = function() {
        var search = location.search;
        search = search.substring(1, search.length);
        var variables = search.split('&');
        var params = {};
        for(var i in variables) {
            var parts = variables[i].split('=');
            parts[0] = decodeURI(parts[0]);
            parts[1] = decodeURI(parts[1]);
            params[parts[0]] = parts[1] === '' ? null : parts[1];
        }
      return params;
    }

    locationSearch.toSearchParams = function(params) {
      var search = "";
      var variables = [];
      if(params !== null && typeof params === 'object') {
        for(var k in params) {
          variables.push( encodeURI(k) + '=' + encodeURI(params[k]) );
        }
      }
      search = '?' + variables.join('&');
      return search;
    }

    locationSearch.setSearchParams = function(params) {
      var search = locationSearch.toSearchParams(params);
      location.search = search;
    }
    global['locationSearchUtils'] = locationSearch;
})(window);